<html>
<body>
<form action="calculator.php" method="GET">
Input:<input type="text" name="expr" />
<input type="submit" />
</form>

<?php
error_reporting(0);
if(($_GET["expr"]))
{
 $expr= $_GET["expr"];
 if(preg_match("#^(-?[0-9]+(.[0-9]+)?[\+\-\*\/])*-?[0-9]+(.[0-9]+)?$#",$expr))
 {
    if(preg_match("#--#",$expr))
       echo "Invalid Expression";
    else
        /*if(preg_match("#\/0[\+\-\*\/]|\/0$#",$expr))
           echo "Cannot divided by zero";
        else*/
        {
           eval("\$ans = $expr;");
           echo "Ans: ".$ans;
        }
 }
 else
    echo "Invalid Expression";
}
?>
</body>
</html>

